<template>
	<view class="regall">
		<image src="../../static/logo.png" class="logo"></image>
		<input type="text" class="reginput" placeholder="请输入用户名" v-model="username" maxlength="10"/>
		<input type="text" class="reginput" placeholder="请输入密码" v-model="password" maxlength="10"/>
		<input type="text" class="reginput" placeholder="确认密码" v-model="confirmpwd" maxlength="10" @blur="check()"/>
		<input type="number" class="reginput" placeholder="手机号" v-model="phone" maxlength="11"/>
		<text v-model="tips">{{tips}}</text>
		<button class="btn" @click="reg()">注册</button>
		
	</view>
</template>

<script>

	
	
	
	export default{
		
		data(){
			return {
				
				username:"",
				password:"",
				confirmpwd:"",
				phone:"",
				tips:"",
			}
		},
		methods:{
			check(){
				if(this.password!=this.confirmpwd){
					uni.showToast({
						title:"两次密码不一致",
						icon:"none",
					})
					return false;
				}
			},
			reg(){
				uni.showLoading({
				    title: '加载中'
				});
				
				
				
				var phoneReg = /(^1\d{10}$)|(^[0-9]\d{7}$)/;
				if(this.username=="" || this.password=="" || this.confirmpwd=="" || this.phone==""){
					uni.showToast({
						title:"请填写完整",
						icon:"none",
						
					})
					return false;
				}
				else if(!phoneReg.test(this.phone)){
					uni.showToast({
						title:"手机号不正确",
						icon:"none",
					})
					return false;
				}
				else if(this.password!=this.confirmpwd){
					uni.showToast({
						title:"两次密码不一致",
						icon:"none",
					})
					return false;
				}
				
				
				uni.request({
					
					
					
					
					url:getApp().globalData.http+"/user/reg",
					method:"POST",
					data:{
						username:this.username,
						password:this.password,
						phone:this.phone,
					},
					header:{
						'content-type':"application/x-www-form-urlencoded"
					},
					
					
					success: (res) => {
						// this.tips=res.data
						// console.log(res)
						if(res.data=="regsuccess"){
							uni.hideLoading();
							uni.navigateBack({
								delta:getCurrentPages().length-2
							});
							uni.showToast({
							title: '注册成功',
							duration: 1500
							});
							
						}
					}
				}) 
			}
		}
	}
	
</script>

<style scoped>
	.regall{
		height: 100%;
		background-color: #FFFFFF;
		overflow: hidden;
		
		width: 300;
		/* margin: 15px; */
		/* border-radius: 15px; */
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.logo{
		width: 74px;
		height: 64px;
		margin-top: 60px;
	}
	.reginput{
		
		border: none;
		background-color: #F4F4F4;
		width: 300px;
		height: 40px;
		border-radius: 15px;
		margin-top: 20px;
		padding-left: 10px;
		font-size: 15px;
	}
	.btn{
		width: 150px;
		height: 40px;
		background-color: #FF8C00;
		border-radius: 70px;
		text-align: center;
		vertical-align:middle;
		line-height: 40px;
		margin-top: 60px;
	}
</style>
